<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>车辆图片上传七牛云</title>
    <script type="text/javascript" src="../js/jquery-3.6.0.min.js"></script>
    <script>
        function uploadfile() {
            $("#fileTypeError").html('');
            //获得文件名称
            var fileName = $('#file_upload').val();
            var formData =  new FormData($('#uploadForm')[0]);

            var carId = $("#carId").val();
            console.log(fileName)
            $.ajax({
                url: '/file/upload',//上传地址
                type: 'POST',
                cache: false,
                data:{
                      carId:carId,
                      file:formData,}
                ,
                    // carId: $("#carId").val()

                 processData: false,
                 contentType: false,
                success: function (rtn) {
                        console.log("上传成功")
                        console.log(rtn.data)
                }
            });
        }
    </script>
</head>
<body>

<form id="uploadForm" >　　<!-- 声明文件上传 -->
    <input id="file_upload" type="file" name="file"/>　　<!-- 定义change事件,选择文件后触发 -->
    <input id="carId" type="text" name="carId" value="1"/>
    <br/><span style="color: red" id="fileTypeError"></span>　　　　<!-- 文件类型错误回显,此处通过前后端两次验证文件类型 -->
    <br/><input type="button" onclick="uploadfile()" value="上传">
</form>
<div></div>
</body>
</html>
